using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VVASABOM
    {
        public DataRow Convert2VASABOM(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryVASABOM(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["VAMMANDANT"] = " ".PadRight(2 ); 
         dwReturn["VAMKOLL"] = " ".PadRight(5 ); 
         dwReturn["VAMART"] = " ".PadRight(24 ); 
         dwReturn["VAMFARBE"] = " ".PadRight(10 ); 
         dwReturn["VAMPOS"] = " ".PadRight(0 ); 
         dwReturn["VAMWAKZ"] = " ".PadRight(1 ); 
         dwReturn["VAMMART"] = " ".PadRight(20 ); 
         dwReturn["VAMVAR"] = " ".PadRight(2 ); 
         dwReturn["VAMDESSIN"] = " ".PadRight(10 ); 
         dwReturn["VAMCOLORI"] = " ".PadRight(10 ); 
         dwReturn["VAMPFARBE"] = " ".PadRight(10 ); 
         dwReturn["VAMMAKEUP"] = " ".PadRight(2 ); 
         dwReturn["VAMSIZE"] = " ".PadRight(2 ); 
         dwReturn["VAMBRT"] = " ".PadRight(0 ); 
         dwReturn["VAMARTNO"] = " ".PadRight(0 ); 
         dwReturn["VAMDART"] = " ".PadRight(20 ); 
         dwReturn["VAMDVAR"] = " ".PadRight(2 ); 
         dwReturn["VAMFILLER"] = " ".PadRight(46 ); 
         dwReturn["VAMAENZL"] = " ".PadRight(0 ); 
         dwReturn["VAMAENB"] = " ".PadRight(8 ); 
         dwReturn["VAMAEND"] = " ".PadRight(0 ); 
         dwReturn["VAMNEUB"] = " ".PadRight(8 ); 
         dwReturn["VAMNEUD"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapVASABOM(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveVASABOM(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryVASABOM(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapVASABOM(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertVASABOM(dwLocal, ITXDBVERSION);
            }
            UpdateVASABOM(dwLocal);
        }
        public void InsertVASABOM(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO VASABOM(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryVASABOM(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM VASABOM WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM VASABOM  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "VASABOM";
            Return = Result;
            return Return;
        }
        public void DeleteVASABOM(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM VASABOM   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateVASABOM(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE VASABOM SET "
                    +"VAMMANDANT= :VAMMANDANT,"
                    +"VAMKOLL= :VAMKOLL,"
                    +"VAMART= :VAMART,"
                    +"VAMFARBE= :VAMFARBE,"
                    +"VAMPOS= :VAMPOS,"
                    +"VAMWAKZ= :VAMWAKZ,"
                    +"VAMMART= :VAMMART,"
                    +"VAMVAR= :VAMVAR,"
                    +"VAMDESSIN= :VAMDESSIN,"
                    +"VAMCOLORI= :VAMCOLORI,"
                    +"VAMPFARBE= :VAMPFARBE,"
                    +"VAMMAKEUP= :VAMMAKEUP,"
                    +"VAMSIZE= :VAMSIZE,"
                    +"VAMBRT= :VAMBRT,"
                    +"VAMARTNO= :VAMARTNO,"
                    +"VAMDART= :VAMDART,"
                    +"VAMDVAR= :VAMDVAR,"
                    +"VAMFILLER= :VAMFILLER,"
                    +"VAMAENZL= :VAMAENZL,"
                    +"VAMAENB= :VAMAENB,"
                    +"VAMAEND= :VAMAEND,"
                    +"VAMNEUB= :VAMNEUB,"
                    +"VAMNEUD= :VAMNEUD,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("VAMMANDANT", OracleType.NVarChar).Value = dwData["VAMMANDANT"].ToString(); 
          or1.Parameters.Add("VAMKOLL", OracleType.NVarChar).Value = dwData["VAMKOLL"].ToString(); 
          or1.Parameters.Add("VAMART", OracleType.NVarChar).Value = dwData["VAMART"].ToString(); 
          or1.Parameters.Add("VAMFARBE", OracleType.NVarChar).Value = dwData["VAMFARBE"].ToString(); 
          or1.Parameters.Add("VAMPOS", OracleType.NVarChar).Value = dwData["VAMPOS"].ToString(); 
          or1.Parameters.Add("VAMWAKZ", OracleType.NVarChar).Value = dwData["VAMWAKZ"].ToString(); 
          or1.Parameters.Add("VAMMART", OracleType.NVarChar).Value = dwData["VAMMART"].ToString(); 
          or1.Parameters.Add("VAMVAR", OracleType.NVarChar).Value = dwData["VAMVAR"].ToString(); 
          or1.Parameters.Add("VAMDESSIN", OracleType.NVarChar).Value = dwData["VAMDESSIN"].ToString(); 
          or1.Parameters.Add("VAMCOLORI", OracleType.NVarChar).Value = dwData["VAMCOLORI"].ToString(); 
          or1.Parameters.Add("VAMPFARBE", OracleType.NVarChar).Value = dwData["VAMPFARBE"].ToString(); 
          or1.Parameters.Add("VAMMAKEUP", OracleType.NVarChar).Value = dwData["VAMMAKEUP"].ToString(); 
          or1.Parameters.Add("VAMSIZE", OracleType.NVarChar).Value = dwData["VAMSIZE"].ToString(); 
          or1.Parameters.Add("VAMBRT", OracleType.NVarChar).Value = dwData["VAMBRT"].ToString(); 
          or1.Parameters.Add("VAMARTNO", OracleType.NVarChar).Value = dwData["VAMARTNO"].ToString(); 
          or1.Parameters.Add("VAMDART", OracleType.NVarChar).Value = dwData["VAMDART"].ToString(); 
          or1.Parameters.Add("VAMDVAR", OracleType.NVarChar).Value = dwData["VAMDVAR"].ToString(); 
          or1.Parameters.Add("VAMFILLER", OracleType.NVarChar).Value = dwData["VAMFILLER"].ToString(); 
          or1.Parameters.Add("VAMAENZL", OracleType.NVarChar).Value = dwData["VAMAENZL"].ToString(); 
          or1.Parameters.Add("VAMAENB", OracleType.NVarChar).Value = dwData["VAMAENB"].ToString(); 
          or1.Parameters.Add("VAMAEND", OracleType.NVarChar).Value = dwData["VAMAEND"].ToString(); 
          or1.Parameters.Add("VAMNEUB", OracleType.NVarChar).Value = dwData["VAMNEUB"].ToString(); 
          or1.Parameters.Add("VAMNEUD", OracleType.NVarChar).Value = dwData["VAMNEUD"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
